<?
@session_start();

require_once("conn.php");

$sql = "SELECT * FROM pch_dealer ORDER BY id DESC";
$query = mysql_query($sql);
?>
<script>
	function getEditDealer(id){
		loadEffect("Loading...");
		$.ajax({
		   type: "POST",
		   url: "dealer.php?cmd=edit",
		   data: "&id="+id+"&t="+Math.random(),
		   success: function(msg){
			   loadEffect(msg);		   
		   }
		});
	}

	function delDealer(id){
		//alert("del "+id);
		if(confirm('Do you want to Delete ?')==true){
			$.ajax({
			   type: "POST",
			   url: "process.php?cmd=delDealer",
			   data: "&id="+id+"&t="+Math.random(),
			   success: function(msg){
				   dealerManage();		   
			   }
			});
		}	
		
	}

	function newDealer(){
		loadEffect("Loading...");
		$.ajax({
		   type: "POST",
		   url: "dealer.php",
		   data: "&t="+Math.random(),
		   success: function(msg){
			   loadEffect(msg);		   
		   }
		});
	}
</script>
<h3>Dealer Manage</h3>
<div align="right" style="width:600px;"><a href="#" onclick="newDealer()">New</a></div>
<table width="600">
	<tr>
		<th>Dealer Name</th>
		<th>Tel</th>
		<th>Fax</th>
		<th>&nbsp;</th>
	</tr>
<?
while($row = mysql_fetch_array($query)){
?>
	<tr>
		<td><?=$row["dealer"]?></td>
		<td><div align="center"><?=$row["tel"]?></div></td>
		<td><div align="center"><?=$row["fax"]?></div></td>
		<td><div align="center"><a href="#" onclick="getEditDealer('<?=$row["id"]?>')">Edit</a>&nbsp;<a href="#" onclick="delDealer('<?=$row["id"]?>')">Del</a></div></td>
	</tr>
<?
}
?>
</table>